﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using StackoverflowNotifier.Properties;

namespace StackoverflowNotifier
{
    public partial class SetProxyForm : Form
    {
        private IWebProxy m_proxy;

        public SetProxyForm()
        {
            InitializeComponent();

            if (Settings.Default.UseProxy)
            {
                rbtnCustomProxy.Enabled = true;
            }
        }

        public IWebProxy Proxy
        {
            get 
            {
                if (Settings.Default.UseProxy == false)
                {
                    m_proxy = WebRequest.DefaultWebProxy;
                }
                else
                {
                    m_proxy = new WebProxy(
                        Settings.Default.WebProxyIP, 
                        (int)Settings.Default.WebProxyPort);
                }

                return m_proxy; 
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Settings.Default.UseProxy = rbtnCustomProxy.Enabled;
            Settings.Default.Save();
        }

        private void rbtnCustomProxy_CheckedChanged(object sender, EventArgs e)
        {
            txtBxWebProxy.Enabled = nudProxyPort.Enabled = rbtnCustomProxy.Checked;
        }
    }
}
